<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>defineProperty</title>
</head>
<body>
    <div id="app">
        hello
    </div>
    <script>
        let data={
          msg:'hello'
        }
        // 模拟vm实例
        let vm={}
        // 创建数据劫持
        Object.defineProperty(vm,'msg',{
          // 可遍历
          enumerable:true,
          // 可配置
          configurable:true,
          // 读取
          get () {
            console.log('get:' , data.msg)
            return data.msg
          },
          set (newValue) {
            if ( data.msg===newValue ) { return  }
            data.msg=newValue
            // 获取dom，并且更新节点
            document.querySelector('#app').textContent=data.msg
          }
        })
        // 测试
        vm.msg = 'hello Vue'
        console.log( vm.msg )
    </script>
</body>
</html>
